package presentation;

import java.awt.Dimension;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.event.KeyEvent;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import controle.ControlJButtonSaveModule;

import abstraction.Cours;
import abstraction.Module;

/** classe qui crée la fenetre qui s'affiche lors de la création ou de la modification d'un module
 * 
 * @author PICOSSON
 *
 */
public class ModuleDialog extends JDialog {

	private static final long serialVersionUID = 1L;

	private JTextField nom;
	private JTextField responsable;
	private int id_module;
	
/**
 * 
 * @param parent
 * @param modele
 * @param creation
 */
	public ModuleDialog(Frame parent, Cours modele, boolean creation) {
		super(parent, "Module", true);
		this.setMinimumSize(new Dimension(200, 100));

		JPanel form = new JPanel(new GridLayout(5, 1));
		form.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));

		form.add(new JLabel("Nom"));
		nom = new JTextField();
		form.add(nom);
		form.add(new JLabel("Responsable"));
		responsable = new JTextField();
		form.add(responsable);
		JPanel buttons = new JPanel();
		JButton save = new JButton("OK");
		save.setMnemonic(KeyEvent.VK_ENTER);
		save.addActionListener(new ControlJButtonSaveModule(this, modele,
				creation));
		buttons.add(save);
		form.add(buttons);
		this.getRootPane().setDefaultButton(save);
		this.getContentPane().add(form);

		if (!creation) {
			Module courante = modele.findModule(modele.getModuleCourant());
			nom.setText(courante.getNom());
			responsable.setText(courante.getResponsable());
			id_module = courante.getId_module();
		}  
		else
			this.id_module = -1;

		this.pack();
		super.setLocationRelativeTo(parent);
	}

	public int getId_module() {
		return id_module;
	}

	public String getNom() {
		return nom.getText();
	}

	public String getResponsable() {
		return responsable.getText();
	}




}
